package com.atguigu.tingshu.order.mapper;

import com.atguigu.tingshu.model.order.OrderInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {

    /**
     * 检查用户是否已经购买了该专辑
     * @param itemType
     * @param userId
     * @param albumId
     * @return
     */
    @Select("SELECT\n" +
            "\tcount(*) \n" +
            "FROM\n" +
            "\t`order_info` \n" +
            "INNER JOIN order_detail\n" +
            "ON order_info.id=order_detail.order_id\n" +
            "WHERE\n" +
            "order_status = '0901' \n" +
            "AND item_type=#{itemType}\n" +
            "AND order_detail.item_id=#{albumId}\n" +
            "AND user_id = #{userId}\n" +
            "AND order_info.is_deleted=0")
    int checkAlbumAndVipTypeItemPadding(@Param("itemType") String itemType, @Param("userId") Long userId, @Param("albumId") Long albumId);


    /**
     * 检查用户是否已经购买了该专辑声音
     * @param itemType
     * @param userId
     * @return
     */
    @Select(" SELECT \n" +
            " order_detail.item_id\n" +
            " FROM `order_info`\n" +
            " INNER JOIN order_detail\n" +
            " ON order_info.id=order_detail.order_id\n" +
            " WHERE  order_info.user_id=#{userId}\n" +
            " AND order_info.item_type=#{itemType}\n" +
            " AND order_info.order_status='0901'")
    List<Long> checkTrackTypeItemPadding(@Param("itemType") String itemType, @Param("userId") Long userId);



    /**
     * 修改订单状态
     * @param orderNo
     * @return
     */
    int updateOrderStatus(@Param("orderNo") String orderNo,@Param("orderStatus") String orderStatusPaid);

    /**
     * 取消订单
     * @param orderNo
     * @return
     */
    void cancelOrder(@Param("orderNo") String orderNo,@Param("orderStatus") String orderStatusPaid);
}
